﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using brockredge.CLASSES;

namespace brockredge
{
    public partial class Search : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           
        }

        protected void searchbtn_Click(object sender, EventArgs e)
        {
            if (ddlarea.Text == "")
                return;
            var sell = 0;
            var rent = 0;
            if (chkSell.Checked)
                sell = 1;
            if (chkRent.Checked)
                rent = 1;
            testDataContext tdc = new testDataContext();
            var advertisementQ = from add in tdc.Advertisements
                                 where tdc.Location_Cities.Any(lc => lc.city_id == (Guid)ddlcity.Text.ToGuid()
                                     && lc.location_id == add.Location_id && (add.IsForRent == rent || add.IsForSell == sell))
                                 select add;

            if (advertisementQ.Count() > 0)
            {
                resultRep.DataSource = advertisementQ;
                resultRep.DataBind();
            }

        }
    }
}